**************************
***	RUN USING STATA 16 ***
**************************
* Purpose: estimate labor market returns to skills and schooling in Ghana
* Last Updated: 06 May 2021

*-------------------------------------------------------------------------------
*	load data
*-------------------------------------------------------------------------------
	
	use "$input\STEP Ghana_working.dta", clear
	
*-------------------------------------------------------------------------------
*	create core indicators
*-------------------------------------------------------------------------------	
	egen literacy = rowmean(PVLIT1-PVLIT10) 

*-------------------------------------------------------------------------------
*	examine error codes, as many respondents' test scores are peculiar
*-------------------------------------------------------------------------------

/*  Exclude using indicator ETS_CORE_PASS which indicates pass/fail among CORE items and determines skip.
	Where a respondent has a missing value for this var (520 of the 2987), it indicates a fieldwork issue
	codes include: 51,52,62,63,64,65,72,73,74, covering refusal, disability, unusual circumstances
	There is a group who refused to begin because they do not read or write the assessment language (codes 61,71)
	This group is recorded as failing the ETS_core module, but still has a PV, because PVs are conditioned on Background vars.	
*/	
	replace literacy = . if ETS_core_pass==. 	
	drop if inlist(final_status_code,61,71) // did not complete literacy test yet have PV based on background characteristics alone
	
*** Now create standardised literacy score, among those that DID some or all of the assessment
	egen lit = std(literacy)
	

*** correct erroneous ln_earnings_h entries
	replace ln_earnings_h = . if earnings_h==0

*-------------------------------------------------------------------------------
*	run through exclusions
*-------------------------------------------------------------------------------		
	drop if m1a_q04<25 // 1) exclude adults under the age of 25
	drop if current==1 // 2) exclude those still in education
	drop if m4c_q17==1 & m4c_q20!=1  // m4c_q17 identifies if employees; then m4c_q20 asks how many, some report just themselves, so they won't be dropped, rest will
	winsor2 ln_earnings_h, replace cuts(1 99) // winsorise top and bottom 1% of earnings
		
*-------------------------------------------------------------------------------
*	setup a education indicators
*-------------------------------------------------------------------------------
		
*** SHS completer
	gen comp_shs = 0
	replace comp_shs = 1 if inrange(m2_q08al,9,14) //teacher training, polytechnic, other tertiary, university
	replace comp_shs = 1 if m2_q08al==7 & m2_q08ag>2 // SHS level and > 2 grades in that level
	replace comp_shs = 1 if m2_q08al==4 & m2_q08ag==7 // old secondary school and >7 grades in that level
		
*** gen public sector employed
	gen public=(pub_emp==1)
	
*** gen anywage
	gen employee=(emp_status==1)
	
*-------------------------------------------------------------------------------
*	Produce Table 3
*-------------------------------------------------------------------------------		

*** setup labels
	label var ln_earnings_h "Earnings"
	label var lit "Literacy"
	label var age "Age"
	label var age2 "Age Squared"
	label var gender "Female"
	label var self_emp "Self Employed"
	label var type_a "Professional"
	label var years_educ_act "Years Schooling"
	label var comp_shs "Completed SHS"
	label var public "Public Sector Employee"
	label var employee "Wage Employment"

	keep if comp_shs==1
	
	eststo clear
	eststo: reg employee lit age age2 gender, vce(robust) 
	eststo: reg employee lit age age2 gender years_educ_act, vce(robust) 
	eststo: reg ln_earnings_h lit age age2 gender, vce(robust) 
	eststo: reg ln_earnings_h lit age age2 gender years_educ_act, vce(robust) 
	eststo: reg ln_earnings_h lit age age2 gender years_educ_act public, vce(robust) 
	esttab using "$table\steps_regs.tex", b(3) se(3) label ///
	title("The return to skill in Ghana's labour market") replace ///
	nogaps star(* 0.10 ** 0.05 *** 0.01) booktabs nocons
	
	
	